package vn.conghuy.talkwithme.responsor.subresponsor;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import vn.conghuy.talkwithme.MyApp;
import vn.conghuy.talkwithme.data.sqlmodel.SqlData;
import vn.conghuy.talkwithme.responsor.responsor.MapResponsor;
import vn.conghuy.talkwithme.responsor.responsor.Responsor;
import vn.conghuy.talkwithme.utils.Utils;
import android.content.Context;

public class MyDirectionSubResponsor {
	
	MapResponsor mapResponsor;
	MyApp myApp;
	Context context;
	
	public MyDirectionSubResponsor(MapResponsor mapResponsor, Context context) {
		this.mapResponsor = mapResponsor;
		this.context = context;
		myApp = (MyApp)context.getApplicationContext();
	}
	
	public String response(String request){
		if(mapResponsor.getRelativeLastResponse() == Responsor.RELATIVE_NONE){
			if(Utils.isStringMatchRegexInArray(request, SqlData.myDirectionAskRegexes)){
				return myDirection();
			}
		}
		return null;
	}
	
	private String myDirection(){
		float degree = myApp.direction;
		if((degree > 0 && degree <= 11.5) || (degree > 348.75 && degree <= 360)){
			return "north";
		}
		else if(degree > 11.5 && degree <= 33.75){
			return "north - north east";
		}
		else if(degree > 33.75 && degree <= 56.25){
			return "north east";
		}
		else if(degree > 56.25 && degree <= 78.75){
			return "east - north east";
		}
		else if(degree > 78.75 && degree <= 101.25){
			return "north";
		}
		else if(degree > 101.25 && degree <= 123.75){
			return "east - south east";
		}
		else if(degree > 123.75 && degree <= 146.25){
			return "south east";
		}
		else if(degree > 146.25 && degree <= 168.75){
			return "south - south east";
		}
		else if(degree > 168.75 && degree <= 191.25){
			return "south";
		}
		else if(degree > 191.25 && degree <= 213.75){
			return "south - south west";
		}
		else if(degree > 213.75 && degree <= 236.25){
			return "south west";
		}
		else if(degree > 236.25 && degree <= 258.75){
			return "west - south west";
		}
		else if(degree > 258.75 && degree <= 281.25){
			return "west";
		}
		else if(degree > 281.25 && degree <= 303.75){
			return "west - north west";
		}
		else if(degree > 303.75 && degree <= 326.25){
			return "north west";
		}
		else if(degree > 326.25 && degree <= 348.75){
			return "north - north west";
		}
		else{
			return "[FAIL]";
		}
	}
}
